

if(typeof util == 'undefined'){
	util = {};
}

util.MyAlimiAjax = jindo.$Class({
    _successCallback : null,
    _failCallback : null,
    _result : null,
    _sUrl : null,
    _sMethod : null,
    _bAsync : null,
    _isSuccessResult : null,
    
    $init : function(url, method, async, successCallback, failCallback) {
    	this._successCallback = successCallback; 
		this._failCallback = failCallback;
		this._sUrl = url;
		this._sMethod = method;
		this._bAsync = async;
    },
    
    runAjax : function(parameter) {
    	this._getAjaxObj().request(parameter);
    },
    
    _onloadFunction : function(res, successCallback) {
		var response = res.json();   
		if(response.message !=null){
			if(response.message.error){
				this._runFailCallback(response);				
			}else if(response.message.result){
				this._runSuccessCallback(response);
			}
		} else{
			alert("호출 결과 값의 형식이 올바르지 않습니다.");
		}
		
	},
	
	_runFailCallback : function(response) {
		if(this._failCallback == null) {
			alert(response.message.error.msg);
			this._isSuccessResult = false;
			return;
		} else {
			this._failCallback();
		}
	},
	
	_runSuccessCallback : function(response) {
		if(this._successCallback == null) {
			this._isSuccessResult = true;
			return;
		} else {
			this._successCallback(response);
		}
	},

	_getAjaxObj : function(){
		return new $Ajax(this._sUrl, {
		    method: this._sMethod,
		    async : this._bAsync,
		    onload:  $Fn(this._onloadFunction, this).bind()
		});
	}
});
